<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title> session_test </title>
    <script>
        function go(uri)
        {

            window.location.href=uri;
        }
    </script>
</head>
<body>
<h1>
    <?php
        session_start();       //之前不能有输出
        if(isset($_POST['username'])&&isset($_POST['password'])) {
            $name = $_POST['username'];
            $pwd= $_POST['password'];
            if($name=='chen'&&$pwd=='5920'){

                echo '登录成功';
                $_SESSION['username']=$name;
                echo '<br/>'.session_id();
            }
            else{
                echo '账号/密码错误';
            }

        }
        elseif(isset($_SESSION['username'])){

            echo 'session登录成功';
            echo '<br/>'.session_id();
            echo '<br/>'.$_SESSION['username'];

        }
        else{       //登录失败

            header('Location:./data_interactive.php');

        }


    ?>
    <p>
    <button type="button" onclick="go('./data_interactive.php')">退出</button>
    </p>










</h1>
</body>

</html>